#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   9:14
# Author     : Y4
# Site       : 
# File       : 014 协程 猴子补丁自动切换.py
# Software   : PyCharm

'''
协程:
生成器每次都要写yield
然后引用了第三方库 greenlet ,但是因为每次都要手动switch
所以就引用了gevent, 猴子补丁
'''



import time
import greenlet
import gevent
from gevent import monkey
monkey.patch_all()

def test1():
    for i in range(5):
        print('a'+str(i))
        time.sleep(1)


def test2():
    for i in range(5):
        print('b'+str(i))
        time.sleep(2)


if __name__ == '__main__':
    g1 = gevent.spawn(test1)
    g2 = gevent.spawn(test2)

    g1.join()
    g2.join()

